package com.ssy.lingxi.marketing.serviceimpl.feign;

import cn.hutool.core.collection.CollUtil;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.service.feign.ISearchFeignService;
import com.ssy.lingxi.marketing.utils.FeignLogUtils;
import com.ssy.lingxi.search.api.feign.IPurchaseFeign;
import com.ssy.lingxi.search.api.feign.ISearchFeign;
import com.ssy.lingxi.search.api.model.request.CommoditySkuRequest;
import com.ssy.lingxi.search.api.model.response.CommoditySkuResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 搜索内部接口
 * @author yzc
 * @version 2.0.0
 * @date 2021/7/19
 */
@Slf4j
@Service
public class SearchFeignServiceImpl implements ISearchFeignService {

    @Resource
    private IPurchaseFeign purchaseFeign;
    @Resource
    private ISearchFeign searchFeign;


    @Override
    public Wrapper<Double> getPurchaseCommodityCount(Long shopId, Long memberId, Long memberRoleId, Long commoditySkuId) {
        Wrapper<Double> commodityPriceBatch = purchaseFeign.getPurchaseCommodityCount(shopId,memberId,memberRoleId,commoditySkuId);
        FeignLogUtils.printLogBySimpleObj("查询购物车商品数量",commodityPriceBatch,"shopId="+shopId,"memberId="+memberId,"memberRoleId="+memberRoleId,"commoditySkuId="+commoditySkuId);
        return commodityPriceBatch;
    }

    @Override
    public Wrapper<List<CommoditySkuResponse>> getCommoditySkuMap(CommoditySkuRequest commoditySkuRequest) {
        Wrapper<List<CommoditySkuResponse>> commodityPriceBatch = searchFeign.getCommoditySkuList(commoditySkuRequest);
        FeignLogUtils.printLog("批量查询商城skus列表",commodityPriceBatch,commoditySkuRequest);
        return commodityPriceBatch;
    }

    @Override
    public  Map<Long,CommoditySkuResponse> getCommoditySkuMap(Long shopId, List<Long> skuIdInList, Long loginMemberId, Long loginRoleId,String provinceCode,String cityCode) {
        CommoditySkuRequest request=new CommoditySkuRequest();
        request.setShopId(shopId);
        request.setSkuIdInList(skuIdInList);
        request.setLoginMemberId(loginMemberId);
        request.setLoginMemberRoleId(loginRoleId);
        request.setProvinceCode(provinceCode);
        request.setCityCode(cityCode);
        Wrapper<List<CommoditySkuResponse>> commodityPriceBatch = searchFeign.getCommoditySkuList(request);
        Map<Long,CommoditySkuResponse> map=null;
        if(commodityPriceBatch.getCode()== ResponseCode.SUCCESS.getCode()&& CollUtil.isNotEmpty(commodityPriceBatch.getData())){
            map=commodityPriceBatch.getData().stream().collect(Collectors.toMap(o ->o.getId(),v->v,(v1,v2)->v1));
        }
        return map;
    }

}
